<template>
  <div class="container"></div>
</template>
<script setup>
import { ref, watch, computed, onMounted, provide, inject } from 'vue'
const props = defineProps([''])
const emit = defineEmits([''])
const getWeatherFn = async () => {
  try {
    const res = await fetch('https://restapi.amap.com/v3/ip?key=高德key')
    const position = await res.json() // 如果数据是JSON格式
    const response = await fetch(`https://restapi.amap.com/v3/weather/weatherInfo?key=高德key&extensions=base&city=${position.city}`)
    const weather = await response.json()
    console.log('当前位置', position)
    console.log('当前天气', weather)
  } catch (error) {
    console.error(error)
  }
}

onMounted(() => {
  getWeatherFn()
})
// 向外暴露属性和方法
defineExpose({})
</script>
<style scoped lang="scss">
.container {
  width: 100%;
  height: 100%;
}
</style>
 